// TB_BPA.cpp: implementation of the CTB_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/TB_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTB_BPA::CTB_BPA()
{
	m_chType = 'T';
	m_chSubType = 'B';
	m_chChangeCode = ' ';

	m_dTch = 0;
	m_dFhp = 0;
	m_dTrh = 0;
	m_dFip = 0;
	m_dTco = 0;
	m_dFlp = 0;
	m_dLambda = 0;

	m_strCardType[0] = 'T';
}

CTB_BPA::CTB_BPA(CTB_BPA &tbBPA):CUnit_BPA(tbBPA)
{
	m_dTch = tbBPA.m_dTch;
	m_dFhp = tbBPA.m_dFhp;
	m_dTrh = tbBPA.m_dTrh;
	m_dFip = tbBPA.m_dFip;
	m_dTco = tbBPA.m_dTco;
	m_dFlp = tbBPA.m_dFlp;
	m_dLambda = tbBPA.m_dLambda;
}

CTB_BPA::~CTB_BPA()
{

}

bool CTB_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CTB_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dTch = StrToDouble(&buffer[16],5,3);
	if(EndOfSec(&buffer[16],5))
		return true;

	m_dFhp = StrToDouble(&buffer[21],5,3);
	if(EndOfSec(&buffer[21],5))
		return true;

	m_dTrh = StrToDouble(&buffer[31],5,3);
	if(EndOfSec(&buffer[31],5))
		return true;

	m_dFip = StrToDouble(&buffer[36],5,3);
	if(EndOfSec(&buffer[36],5))
		return true;

	m_dTco = StrToDouble(&buffer[46],5,3);
	if(EndOfSec(&buffer[46],5))
		return true;

	m_dFlp = StrToDouble(&buffer[51],5,3);
	if(EndOfSec(&buffer[51],5))
		return true;

	m_dLambda = StrToDouble(&buffer[76],4,2);
	if(EndOfSec(&buffer[76],4))
		return true;

	return true;
}

bool CTB_BPA::UpdateEx(char *buffer)
{
	int i;

	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CTB_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dTch,&buffer[16],5,3);
	DoubleToStr(m_dFhp,&buffer[21],5,3);
	for (i=26;i<31;++i)
	{
		buffer[i] = ' ';
	}
	DoubleToStr(m_dTrh,&buffer[31],5,3);
	DoubleToStr(m_dFip,&buffer[36],5,3);
	for (i=41;i<46;++i)
	{
		buffer[i] = ' ';
	}
	DoubleToStr(m_dTco,&buffer[46],5,3);
	DoubleToStr(m_dFlp,&buffer[51],5,3);
	for (i=56;i<76;++i)
	{
		buffer[i] = ' ';
	}
	DoubleToStr(m_dLambda,&buffer[76],4,2);

	return true;
}